package com.haierCamera.customapplication.ui.service;

import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;

import timber.log.Timber;

public class OPPOPushMessageActivity extends AppCompatActivity {

    public String type = "";
    public String data = "";
    public String innerUrl = "";
    HashMap<String, String> hm;
    private String classID;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       /* // 取参数值
        if (getIntent().getExtras() != null) {
            // 取参数值
            Bundle bundle = getIntent().getExtras();
            Set<String> set = bundle.keySet();
            hm = new HashMap<>();
            if (set != null) {
                for (String key : set) {
                    hm.put(key, bundle.getString(key));
                    Timber.i("NPL111= %s %s", key, bundle.getString(key));
                }
            }
            if (hm.size() > 0) {
                //解析当前的HashMap对象，可以获取具体的数据
                //todo 要和后台约定key值，现在暂时是key1、key2
                if (set.contains("type")) {
                    type = hm.get("type");
                }
                if (set.contains("data")) {
                    data = hm.get("data");
                }
                if (set.contains("innerUrl")) {
                    innerUrl = hm.get("innerUrl");
                }
                //根据当前type类型去执行不同的操作
                Timber.i("clickToApp %s %s", type, data);
                try {
                    JSONObject jsonObject = new JSONObject(data);
                    Intent intent = new Intent();
                    //0校园公告1班级公告2校园通知3班级通知4问卷调查
                    if ("0".equals(type)) {
                        intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.publics.SchoolNoticePublicActivity"));
                        intent.putExtra("flag", 2).putExtra("title", "校园公告").putExtra("type", 1);
                    } else if ("1".equals(type)) {
                        intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.publics.SchoolNoticePublicActivity"));
                        intent.putExtra("flag", 2).putExtra("title", "班级公告").putExtra("type", 2);
                    } else if ("2".equals(type)) {
                        intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.publics.SchoolNoticePublicActivity"));
                        intent.putExtra("flag", 1).putExtra("title", "校园通知").putExtra("type", 2);
                    } else if ("3".equals(type)) {
                        intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.publics.SchoolNoticePublicActivity"));
                        intent.putExtra("flag", 1).putExtra("title", "班级通知").putExtra("type", 3);
                    } else if ("4".equals(type)) {
                        intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.publics.SchoolNoticePublicActivity"));
                        intent.putExtra("flag", 4).putExtra("title", "问卷调查").putExtra("type", 2);
                    } else if ("5".equals(type)) {
                        intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.new_leave.leave.ApplyForLeaveListActivity"));
                        intent.putExtra("title", "我的请假");
                    } else if ("6".equals(type)) {
                        intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.leave.LeaveStudentActivity"));
                        intent.putExtra("title", "批学生假");
                    } else if ("7".equals(type)) {
                        intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.leave.LeaveTeachersActivity"));
                        intent.putExtra("title", "批假初审").putExtra("type", 1);
                    } else if ("8".equals(type)) {
                        intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.leave.LeaveTeachersActivity"));
                        intent.putExtra("title", "批假终审").putExtra("type", 2);
                    } else if ("9".equals(type)) {
                        intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.is_on_duty.DutyCalendarActivity"));
                    } else if ("10".equals(type)) {
                        //intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.is_on_duty.DutyCalendarActivity"));
                    } else if ("11".equals(type)) {
                        String classID = jsonObject.getString("classID");
                        intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.bed.BedroomMsgActivity"));
                        intent.putExtra("classId", classID);
                    } else if ("12".equals(type)) {
                        intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.visitors.VisitorsListActivity"));
                    } else if ("13".equals(type)) {
                        intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.leave_message.LeaveMessageTeacherActivity"));
                    } else if ("14".equals(type)) {
                        //学生留言
                        intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.leave_message.LeaveMessageStudentActivity"));
                    } else if ("15".equals(type)) {
                        //教师带队 com.komlin.commonedition.ui.lead_the_tean
                        intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.lead_the_tean.TeachersLeadTheTeamActivity"));
                    } else if ("16".equals(type)) {
                        //待处理保修
                        intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.matters.MattersListActivity"));
                    } else if ("17".equals(type)) {
                        //安全巡查 com.komlin.commonedition.ui.safety_patrol
                        intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.safety_patrol.SafetyPatrolActivity"));
                    } else if ("18".equals(type)) {
                        //代换课申请 com.komlin.commonedition.ui.safety_patrol
                        intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.lesson_change.LessonChangeListActivity"));
                    } else if ("19".equals(type)) {
                        //开发者邀请 com.komlin.commonedition.ui.safety_patrol
                        intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.lesson_change.LessonChangeInviteActivity"));
                    } else {
                        intent.setComponent(new ComponentName("com.komlin.iwatchteacher.commonedition", "com.komlin.commonedition.ui.main.MainActivity"));
                    }
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    intent.setAction("android.intent.action.VIEW");
                    new Timer().schedule(new TimerTask() {
                        @Override
                        public void run() {
                            startActivity(intent);
                            finish();
                        }
                    }, 1000);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }*/
    }

}


